package com.cdn.nodes.controller;


import com.alibaba.fastjson2.JSONObject;
import com.cdn.common.redis.service.RedisService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RestController
@RequestMapping
public class TestController {

    @Resource
    private RedisService redisService;

    @GetMapping("testGet")
    public JSONObject getNodeResourece(){

        String key = "node:" + 1;  // Redis 存储的 key 格式

        // 从 Redis 获取节点数据
        JSONObject nodeDataJson = redisService.getCacheObject(key);

        // 如果数据存在
        if (nodeDataJson != null) {
            // 解析 JSON 字符串为 JSONObject
            return nodeDataJson;
        } else {
            System.out.println("节点数据不存在，key: " + key);
        }

        return null;
    }
}
